package com.zhss.eshop.schedule.mapper;

import com.zhss.eshop.schedule.domain.model.ScheduleGoodsAllocationStock;
import org.apache.ibatis.annotations.*;

@Mapper
public interface ScheduleGoodsAllocationStockMapper {
    int deleteByPrimaryKey(Long id);

    int insertSelective(ScheduleGoodsAllocationStock record);

    ScheduleGoodsAllocationStock selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(ScheduleGoodsAllocationStock record);

    /**
     * 根据商品sku id查询商品库存
     * @param goodsAllocationId 货位id
     * @param goodsSkuId 商品sku id
     * @return 商品库存
     */
    @Select("SELECT "
            + "id,"
            + "goods_allocation_id,"
            + "goods_sku_id,"
            + "available_stock_quantity,"
            + "locked_stock_quantity,"
            + "output_stock_quantity,"
            + "gmt_create,"
            + "gmt_modified "
            + "FROM schedule_goods_allocation_stock "
            + "WHERE goods_sku_id=#{goodsSkuId} "
            + "AND goods_allocation_id=#{goodsAllocationId}")
    @Results({
            @Result(column = "id", property = "id", id = true),
            @Result(column = "goods_sku_id", property = "goodsSkuId"),
            @Result(column = "goods_allocation_id", property = "goodsAllocationId"),
            @Result(column = "available_stock_quantity", property = "availableStockQuantity"),
            @Result(column = "locked_stock_quantity", property = "lockedStockQuantity"),
            @Result(column = "output_stock_quantity", property = "outputStockQuantity"),
            @Result(column = "gmt_create", property = "gmtCreate"),
            @Result(column = "gmt_modified", property = "gmtModified")
    })
    ScheduleGoodsAllocationStock getBySkuId(
            @Param("goodsAllocationId") Long goodsAllocationId,
            @Param("goodsSkuId") Long goodsSkuId);
}
